package com.siwei.mes.controller.experiment;

import com.siwei.mes.entity.experiment.ExperimentSignature;
import com.siwei.mes.service.experiment.ExperimentSignatureService;
import org.springframework.web.bind.annotation.*;
import com.siwei.mes.common.query.PageQuery;
import com.siwei.mes.common.result.ApiResult;
import com.siwei.mes.common.result.Json;
import com.siwei.mes.common.validator.AddGroup;
import com.siwei.mes.common.validator.PageGroup;
import com.siwei.mes.common.validator.UpdateGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.validation.annotation.Validated;

import static com.siwei.mes.common.exception.handler.MessageHandler.assertTrue;

import javax.annotation.Resource;

/**
 * 试验台账与电子签名关系相关
 *
 * @author makejava
 * @since 2025-10-28 23:46:06
 */
@Api(value = "试验台账与电子签名关系")
@RestController
@RequestMapping("experimentSignature")
public class ExperimentSignatureController {
    @Resource
    private ExperimentSignatureService experimentSignatureService;

    @ApiOperation(value = "新增试验台账与电子签名关系")
    @PostMapping("/create")
    public Json create(@RequestBody @Validated(AddGroup.class) ExperimentSignature entity) {
        return Json.succ().data(ApiResult.addColumn("id", experimentSignatureService.create(entity)));
    }

    @ApiOperation(value = "修改试验台账与电子签名关系")
    @PostMapping("/update")
    public Json update(@RequestBody @Validated(UpdateGroup.class) ExperimentSignature entity) {
        experimentSignatureService.update(entity);
        return Json.succ().data(new ApiResult());
    }

    @ApiOperation(value = "删除试验台账与电子签名关系")
    @PostMapping("/delete")
    public Json delete(@RequestBody ExperimentSignature entity) {
        experimentSignatureService.delete(entity.getId());
        return Json.succ().data(new ApiResult());
    }

    @ApiOperation(value = "分页获取试验台账与电子签名关系")
    @PostMapping("/page")
    public Json appPage(@RequestBody @Validated(PageGroup.class) PageQuery<ExperimentSignature, ExperimentSignature> query) {
        return Json.succ().data(experimentSignatureService.getPage(query));
    }

    @ApiOperation(value = "根据主键id获取试验台账与电子签名关系")
    @GetMapping("loadById")
    public Json loadById(@RequestParam("id") Long id) {
        return Json.succ().data(experimentSignatureService.loadById(id));
    }

    @ApiOperation(value = "获取所有试验台账与电子签名关系")
    @PostMapping("getAll")
    public Json getAll(@RequestBody ExperimentSignature entity) {
        return Json.succ().data(ApiResult.addList(experimentSignatureService.getAll(entity)));
    }

}
